package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.CurrencyBlock;
import com.ruoyi.web.service.ICurrencyBlockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 区块Controller
 *
 * @author ruoyi
 * @date 2022-12-30
 */
@RestController
@RequestMapping("/web/block")
public class CurrencyBlockController extends BaseController {
    @Autowired
    private ICurrencyBlockService currencyBlockService;

    /**
     * 查询区块列表
     */
    @PreAuthorize("@ss.hasPermi('web:block:list')")
    @GetMapping("/list")
    public TableDataInfo list(CurrencyBlock currencyBlock) {
        startPage();
        List<CurrencyBlock> list = currencyBlockService.selectCurrencyBlockList(currencyBlock);
        return getDataTable(list);
    }

    /**
     * 导出区块列表
     */
    @PreAuthorize("@ss.hasPermi('web:block:export')")
    @Log(title = "区块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CurrencyBlock currencyBlock) {
        List<CurrencyBlock> list = currencyBlockService.selectCurrencyBlockList(currencyBlock);
        ExcelUtil<CurrencyBlock> util = new ExcelUtil<CurrencyBlock>(CurrencyBlock.class);
        util.exportExcel(response, list, "区块数据");
    }

    /**
     * 获取区块详细信息
     */
    @PreAuthorize("@ss.hasPermi('web:block:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(currencyBlockService.selectCurrencyBlockById(id));
    }

    /**
     * 新增区块
     */
    @PreAuthorize("@ss.hasPermi('web:block:add')")
    @Log(title = "区块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CurrencyBlock currencyBlock) {
        return toAjax(currencyBlockService.insertCurrencyBlock(currencyBlock));
    }

    /**
     * 修改区块
     */
    @PreAuthorize("@ss.hasPermi('web:block:edit')")
    @Log(title = "区块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CurrencyBlock currencyBlock) {
        return toAjax(currencyBlockService.updateCurrencyBlock(currencyBlock));
    }

    /**
     * 删除区块
     */
    @PreAuthorize("@ss.hasPermi('web:block:remove')")
    @Log(title = "区块", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(currencyBlockService.deleteCurrencyBlockByIds(ids));
    }
}
